snapshot: Handle clip region as part of the state
authorBenjamin Otte <otte@redhat.com>
Tue, 13 Dec 2016 00:44:52 +0000 (01:44 +0100)
committerBenjamin Otte <otte@redhat.com>
Tue, 20 Dec 2016 17:01:10 +0000 (18:01 +0100)
This is in preparation for further changes.

gtk/gtksnapshot.c
gtk/gtksnapshotprivate.h

index 946c308fef070e548aeaeab688631da9a9358faa..331e9804d33c845dbc357dc1ad8a8298d5fb18d5 100644 (file)
@@ -50,6 +50,7 @@
 
 static GtkSnapshotState *
 gtk_snapshot_state_new (GtkSnapshotState *parent,
+                        cairo_region_t   *clip,
                         GskRenderNode    *node)
 {
   GtkSnapshotState *state;
@@ -58,6 +59,8 @@ gtk_snapshot_state_new (GtkSnapshotState *parent,
 
   state->node = node;
   state->parent = parent;
+  if (clip)
+    state->clip_region = cairo_region_reference (clip);
 
   return state;
 }
@@ -65,6 +68,9 @@ gtk_snapshot_state_new (GtkSnapshotState *parent,
 static void
 gtk_snapshot_state_free (GtkSnapshotState *state)
 {
+  if (state->clip_region)
+    cairo_region_destroy (state->clip_region);
+
   g_slice_free (GtkSnapshotState, state);
 }
 
@@ -81,7 +87,6 @@ gtk_snapshot_init (GtkSnapshot          *snapshot,
 
   snapshot->state = NULL;
   snapshot->renderer = renderer;
-  snapshot->clip_region = clip;
   snapshot->root = gsk_container_node_new ();
 
   if (name)
@@ -98,7 +103,7 @@ gtk_snapshot_init (GtkSnapshot          *snapshot,
       g_free (str);
     }
 
-  snapshot->state = gtk_snapshot_state_new (NULL, snapshot->root);
+  snapshot->state = gtk_snapshot_state_new (NULL, (cairo_region_t *) clip, snapshot->root);
 }
 
 GskRenderNode *
@@ -130,7 +135,7 @@ gtk_snapshot_push_node (GtkSnapshot   *snapshot,
 {
   g_return_if_fail (gsk_render_node_get_node_type (node) == GSK_CONTAINER_NODE);
 
-  snapshot->state = gtk_snapshot_state_new (snapshot->state, node);
+  snapshot->state = gtk_snapshot_state_new (snapshot->state, snapshot->state->clip_region, node);
 }
 
 /**
@@ -374,10 +379,13 @@ gtk_snapshot_clips_rect (GtkSnapshot           *snapshot,
   graphene_rect_t offset_bounds;
   cairo_rectangle_int_t rect;
 
+  if (snapshot->state->clip_region == NULL)
+    return FALSE;
+
   graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, &offset_bounds);
   rectangle_init_from_graphene (&rect, &offset_bounds);
 
-  return cairo_region_contains_rectangle (snapshot->clip_region, &rect) == CAIRO_REGION_OVERLAP_OUT;
+  return cairo_region_contains_rectangle (snapshot->state->clip_region, &rect) == CAIRO_REGION_OVERLAP_OUT;
 }
 
 /**
index 74fbf9f5f8d5c9080e1466919820bcddfb2df827..54b3a6bbbec1660c719c96ac7efbce127f0bd976 100644 (file)
@@ -29,6 +29,7 @@ struct _GtkSnapshotState {
 
   GskRenderNode         *node;
 
+  cairo_region_t        *clip_region;
   double                 translate_x;
   double                 translate_y;
 };
@@ -38,7 +39,6 @@ struct _GtkSnapshot {
 
   GskRenderNode         *root;
   GskRenderer           *renderer;
-  const cairo_region_t  *clip_region;
 };
 
 void            gtk_snapshot_init               (GtkSnapshot             *state,